package de.tub.bazinga.object.particle;

import java.util.Random;

import processing.core.PVector;
import de.tub.bazinga.object.Color;

public class CentrifugalParticleBehavior implements ParticleBehavior {

	private final Random random;
	private final float minVelocity;
	private final float maxVelocity;
	private final int minLifeTime;
	private final int maxLifeTime;

	public CentrifugalParticleBehavior(float minVel, float maxVel,
			int minLifeTime, int maxLifeTime) {
		random = new Random(System.currentTimeMillis());

		minVelocity = minVel;
		maxVelocity = maxVel;
		this.minLifeTime = minLifeTime;
		this.maxLifeTime = maxLifeTime;
	}

	@Override
	public PVector getStartVelocity() {
		float velocity = random.nextFloat() * (maxVelocity - minVelocity)
				+ minVelocity;
		float angle = randomAngle();

		float xVel = (float) (velocity * Math.cos(angle));
		float yVel = (float) (velocity * Math.sin(angle));
		return new PVector(xVel, yVel);
	}

	@Override
	public PVector getAccleration(PVector position) {
		return new PVector(0, 0);
	}

	@Override
	public int getLifeTime() {
		return random.nextInt(maxLifeTime - minLifeTime) + minLifeTime;
	}

	private float randomAngle() {
		return random.nextFloat() * 360;
	}

	@Override
	public PVector getVelocity(PVector currentVelocity, PVector accleration) {
		return currentVelocity;
	}

	@Override
	public Color getColor() {
		return new Color(random.nextInt(255), random.nextInt(255),
				random.nextInt(255), 255);
	}

}
